package com.cg.controller;

import com.cg.dto.*;
import com.cg.service.PatientUserService;
import com.cg.vo.LoginPatientUserVo;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (PatientUser)表控制层
 *
 * @author chengong
 * @since 2023-12-31 13:47:45
 */
@RestController
@RequestMapping("/patientUser")
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)//代理使用默认的
public class PatientUserController {
    /**
     * 服务对象
     */
    @Resource
    private PatientUserService patientUserService;

    /**
     * 获取注册需要的手机验证码
     */
    @PostMapping("/getCode")
    public Result getCode(@RequestBody PhoneDto phoneDto){
        return patientUserService.getCode(phoneDto.getPhone());
    }


    /**
     * 注册用户
     */
    @PostMapping("/createPatientUser")
    public Result createPatientUser(@RequestBody RegisterPatientUserDto registerPatientUserDto){
        return patientUserService.createPatientUser(registerPatientUserDto);
    }


    /**
     * 获取登录的手机验证码
     */
    @PostMapping("/getLoginCode")
    public Result getLoginCode(@RequestParam("phone") String phone){
        return patientUserService.getLoginCode(phone);
    }


    /**
     * 患者登录
     */
    @PostMapping("/loginPatientUser")
    public Result<LoginPatientUserVo> loginPatientUser(@RequestBody LoginPatientUserDto loginPatientUserDto){
        Result<LoginPatientUserVo> loginPatientUserVoResult = patientUserService.loginPatientUser(loginPatientUserDto);
        return loginPatientUserVoResult;
    }


    /**
     * 修改密码
     */
    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody UpdatePasswordDto updatePasswordDto){
        return patientUserService.updatePassword(updatePasswordDto);
    }
}

